package com.linjuke.childay.biz.dao.sqlite;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase.CursorFactory;

public class ItemSQLiteOpenHelper extends SQLiteOpenHelper {

	public ItemSQLiteOpenHelper(Context context, String name,
			CursorFactory factory, int version) {
		super(context, name, factory, version);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		initDb(db);
	}
	
	private void initDb(SQLiteDatabase db) {
		String createTableSQL = "create table bsl_item ("+
				"id bigint primary key not null,"+
				"user_id bigint not null default 0,"+
				"price bigint not null default 0,"+
				"phone varchar(40) not null,"+
				"cat_id int not null default 0,"+
				"description varchar(1024),"+
				"status tinyint default 0 not null,"+
				"longitude int not null default 0,"+
				"latitude int not null default 0,"+
				"altitude int not null default 0,"+
				"pic1 varchar(1024),	"+
				"pic2 varchar(1024),	"+
				"pic3 varchar(1024),	"+
				"gmt_create_server datetime not null,"+
				"gmt_create_local datetime not null,"+
				"gmt_modified_server datetime not null,"+
				"gmt_modified_local datetime not null"+
			");";
			db.execSQL(createTableSQL);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		 String dropSQL = "drop table if exists bsl_item";
		 db.execSQL(dropSQL);
		 initDb(db);
	}

}
